package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2019-11-26 22:12
 */
public class Q7 {
    public int reverse(int x) {
        boolean isNegative = false;
        if(x < 0){
            x = -x;
            isNegative = true;
        }

        StringBuilder sb = new StringBuilder();
        while(x > 0){
            sb.append(x % 10);
            x /= 10;
        }

        try {
            return isNegative ? -1 * Integer.parseInt(sb.toString()) : Integer.parseInt(sb.toString());
        } catch (Exception e){
            return 0;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Q7().reverse(199999));
    }
}
